#!/usr/bin/ruby

$ord_A = "A".ord

def name2addr(name)
	addr = 0
	name.each_char do |c|
		addr = addr*26 + c.ord - $ord_A + 1
	end
	return addr
end

def addr2name(addr)
	name = ""
	while addr != 0
		addr -= 1
		name = (addr%26 + $ord_A).chr + name
		addr /= 26
	end
	return name
end

gets	# skip first line
while gets
	line = $_.chomp
	if m = /R(\d+)C(\d+)/.match(line)
		puts addr2name(m[2].to_i) + m[1]
	elsif m = /([A-Z]+)(\d+)/.match(line)
		puts "R" + m[2] + "C" + name2addr(m[1]).to_s
	else
		abort "bad_format"
	end
end
